package com.tinyseed.emcp.api.basicdata.rest;

import com.tinyseed.emcp.api.basicdata.model.MonitorRelationInputDTO;
import com.tinyseed.emcp.api.basicdata.model.OrganizeNodeInputDTO;
import com.tinyseed.emcp.api.basicdata.model.OrganizeNodeOutputDTO;
import com.tinyseed.emcp.api.basicdata.service.DeviceGroupService;
import com.tinyseed.hmxx.common.base.BaseController;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/***
 * @ClassName: DeviceGroupController
 * @Description: TODO
 * @Auther: Harlan.Xiong
 * @Date: 2019-11-27 21:46
 * @version : V1.0
 */
@Controller
@RequestMapping("/deviceGroup")
public class DeviceGroupController extends BaseController {

    @Autowired
    private DeviceGroupService deviceGroupService;

    /**
     * 获取设备分组界面树结构
     */
    @PostMapping(value = "/queryTree")
    @ResponseBody
    public ResponseEntity queryTree() {
        List<OrganizeNodeOutputDTO> dtos = deviceGroupService.findOrganizeTree();
        return new ResponseEntity<>(dtos, HttpStatus.OK);
    }

    /**
     * 分页信息
     */
    @RequestMapping(value = "/page")
    @ResponseBody
    public ResponseEntity page(OrganizeNodeInputDTO request, int limit, int page) {
        return new ResponseEntity<>(deviceGroupService.page(request, limit, page), HttpStatus.OK);
    }

    @GetMapping(value = "list")
    @ApiOperation("分页查询")
    public ResponseEntity list(int size, int current) {
        return new ResponseEntity<>(deviceGroupService.findIndustryByPage(current, size),HttpStatus.OK);
    }

    @RequestMapping(value = "getEditSelectData")
    @ResponseBody
    @ApiOperation("查询下拉框检测点数据")
    private ResponseEntity getEditSelectData(Long shopId) {
        return new ResponseEntity<>(deviceGroupService.getEditSelectData(shopId),HttpStatus.OK);
    }

    /**
     * 保存
     */
    @PostMapping(value = "/save")
    @ResponseBody
    public ResponseEntity save(@RequestBody MonitorRelationInputDTO monitorRelationInputDTO) {
        deviceGroupService.save(monitorRelationInputDTO);
        return new ResponseEntity<>(HttpStatus.OK);
    }

    /**
     * 删除
     */
    @PostMapping(value = "/delete")
    @ResponseBody
    public ResponseEntity delete(Long produceId, Long polluteId) {
        return new ResponseEntity<>(deviceGroupService.delete(produceId, polluteId),HttpStatus.OK);
    }
}
